<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @copyright   Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<form id="edit_form" method="post" action="<?php echo $this->getSaveUrl() ?>">
    <?php echo $this->getBlockHtml('formkey')?>
    <?php $_order = $this->getInvoice()->getOrder() ?>
    <?php echo $this->getChildHtml('order_info') ?>
    <?php if (!$_order->getIsVirtual()): ?>
    <div class="clearfix">
    <?php endif; ?>

    <div class="order-payment-method<?php if ($_order->getIsVirtual()): ?> order-payment-method-virtual<?php endif; ?>">
        <div class="fieldset-wrapper">
            <div class="fieldset-wrapper-title">
                <span class="title"><?php echo __('Payment Information') ?></span>
            </div>
            <div><?php echo $this->getChildHtml('order_payment') ?></div>
            <div class="order-payment-currency"><?php echo __('The order was placed using %1.', $_order->getOrderCurrencyCode()) ?></div>
            <div class="order-payment-additional"><?php echo $this->getChildHtml('order_payment_additional'); ?></div>
        </div>
    </div>
    <?php if (!$_order->getIsVirtual()): ?>
    <div class="order-shipping-address">
        <?php /*Shipping Address */ ?>
        <div class="fieldset-wrapper">
            <div class="fieldset-wrapper-title">
                <span class="title"><?php echo __('Shipping Information') ?></span>
            </div>
            <div class="shipping-description-wrapper">
                <div class="shipping-description-title"><?php echo $this->escapeHtml($_order->getShippingDescription()) ?></div>
                <div class="shipping-description-content">
                    <?php echo __('Total Shipping Charges'); ?>:

                    <?php if ($this->helper('Magento\Tax\Helper\Data')->displayShippingPriceIncludingTax()): ?>
                        <?php $_excl = $this->displayShippingPriceInclTax($_order); ?>
                    <?php else: ?>
                        <?php $_excl = $this->displayPriceAttribute('shipping_amount', false, ' '); ?>
                    <?php endif; ?>
                    <?php $_incl = $this->displayShippingPriceInclTax($_order); ?>

                    <?php echo $_excl; ?>
                    <?php if ($this->helper('Magento\Tax\Helper\Data')->displayShippingBothPrices() && $_incl != $_excl): ?>
                        (<?php echo __('Incl. Tax'); ?> <?php echo $_incl; ?>)
                    <?php endif; ?>
                </div>
            </div>
            <?php if ($this->canCreateShipment() && $this->canShipPartiallyItem()): ?>
            <div>
                <label for="invoice_do_shipment" class="normal"><?php echo __('Create Shipment') ?></label>
                <input type="checkbox" name="invoice[do_shipment]" id="invoice_do_shipment" value="1" <?php echo $this->hasInvoiceShipmentTypeMismatch()?' disabled="disabled"':'' ?> />
            </div>
            <?php if ($this->hasInvoiceShipmentTypeMismatch()): ?>
                <small><?php echo __('Invoice and shipment types do not match for some items on this order. You can create a shipment only after creating the invoice.') ?></small>
                <?php endif; ?>
            <?php endif; ?>
            <div id="tracking" style="display:none;"><?php echo $this->getChildHtml('tracking',false) ?></div>
        </div>
    </div>
    <?php endif; ?>

    </div>

    <div id="invoice_item_container">
        <?php echo $this->getChildHtml('order_items') ?>
    </div>
</form>
<script type="text/javascript">
require(['prototype'], function(){

//<![CDATA[
    var createShipment = $('invoice_do_shipment');
    if (createShipment) {
        createShipment.observe('click', function(e){
            if (createShipment.checked) {
                document.getElementById('tracking').style.display = 'block';
            } else {
                document.getElementById('tracking').style.display = 'none'
            }
        })
    }

    /*forced creating of shipment*/
    var forcedShipmentCreate = <?php echo $this->getForcedShipmentCreate() ?>;
    var shipmentElement = $('invoice_do_shipment');
    if (forcedShipmentCreate && shipmentElement) {
        shipmentElement.checked = true;
        shipmentElement.disabled = true;
        document.getElementById('tracking').style.display = 'block';
    }

    window.createShipment = createShipment;
    window.forcedShipmentCreate = forcedShipmentCreate;
    window.shipmentElement = shipmentElement;
//]]>

});
</script>
